<%= form_for(@vote) do |f| %>
  <% if @vote.errors.any? %>
    <div id="error_explanation">
      <h2><%= pluralize(@vote.errors.count, "error") %> prohibited this vote from being saved:</h2>

      <ul>
      <% @vote.errors.full_messages.each do |msg| %>
        <li><%= msg %></li>
      <% end %>
      </ul>
    </div>
  <% end %>

<fieldset>
    <legend>基本信息 </legend>
  <div class="field">
    <%= f.label :title,"本次投票名称" %><br />
    <%= f.text_field :title %>
  </div>
  <div class="field">
    <%= f.label :subtitle,"本次投票副标题" %><br />
    <%= f.text_field :subtitle %>
  </div>
  <div class="field">
    <%= f.label :vtype,"本次投票类型" %><br />
    <%= f.select :vtype,options_for_select([['选择投票类型', ''],['投票', 'vote'], ['评分', 'mark']]) %>
  </div>
  <div class="field">
    <%= f.label :note,"本次投票的详细介绍" %><br />
    <%= f.text_area :note,:rows => 2 %>
  </div>
</fieldset>

<%= f.fields_for :sections do |builder| %>
      <%= render "section_fields", :f => builder %>  
<% end %>  
<%= link_to_function("添加选票单", "add_field(this)")%>

  <div class="actions">
    <%= f.submit %>
  </div>
<% end %>
<script type="text/javascript">
$(document).ready(function(){
  $(".forvote").hide();
  $(".formark").hide();
  $("#vote_vtype").live('change',function(){
     //alert($(this).val());
     if($(this).val() != 'vote'){
      $(".forvote").hide();
      $(".forvote input").val('');
      $(".formark").show();
     }
     if($(this).val() != 'mark'){
      $(".formark").hide();
      $(".formark input").val('');
      $(".forvote").show();
     }

  });

 $(".selectcandidate select").live('change',function(){
    var len = $(this).children(":checked").length;
    $(this).parent().next(".maxcandidate").find("span.countcandidate").text(len);
    $(this).parent().next(".maxcandidate").find("input").val(len).attr("max",len);

    $(this).parent().next().next(".mincandidate").find("input").attr("max",len);

    

  });

});
</script>

